local path "C:\Users\pgi1\Dropbox\Coal 2021 _ Joe Peter\Bank Regressions\"
cd "`path'\data"
set seed 100
set more off
clear



use  loan_year_vars_dataset, clear

//edit if lender=="BofA Securities"

bysort ultimateparentid year: keep if _n==1
xtset ultimateparentid year

keep if year>=2000 & year<=2020
keep if mi(minpolicyyear) | year<minpolicyyear




est clear

xtreg loans_mtr_ln pretreated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e1
estadd local fes "Bank and Year"

xtreg loans_mtr_ln pretreated_company loans_related_lag3_ln loans_total_lag3_ln log_assets asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e2
estadd local fes "Bank and Year"


xtreg loans_mtr_ln pretreated_project loans_related_lag3_ln loans_total_lag3_ln  log_assets  asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e3
estadd local fes "Bank and Year"


xtreg loans_mtr_ln pretreated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e4
estadd local fes "Bank and Year"

esttab e1 e2 e3 e4 using "`path'\tables\table-4.rtf",  replace compress nogaps se onecell b(3) modelwidth(6) ///
title("Table IA4: Number of Loans to MTR-affiliated borrowers in the Years Before Announcing a Policy") mtitles( "Any"  "Company" "Project" "Enhanced" ) ///
stats(fes r2_a  N , fmt(%9.0fc %9.3fc %9.0fc ) labels("Fixed Effects" "Adj. R-squared" "Observations" ) ) ///
label collabels(none)  starlevels(* 0.10 ** 0.05 *** 0.01) nonote ///
order(pretreated pretreated_company pretreated_project pretreated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln) keep(pretreated pretreated_company pretreated_project pretreated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln)
